package com.spring.shops.admin.controller.system;

import com.spring.shops.model.dto.SysRoleDTO;
import com.spring.shops.model.dto.SysSaveRoleDTO;
import com.spring.shops.model.result.IPageIndexImg;
import com.spring.shops.model.result.ServerResponseEntityVoid;
import com.spring.shops.model.vo.SysRoleVO;
import com.spring.shops.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//系统管理->角色管理
@RestController
@RequestMapping(value = "/sys/role", produces = "application/json; charset=utf-8")
public class SysRoleController {
    @Autowired
    private RoleService service;

    /**
     * 列出所有的角色
     * @return
     */
    @GetMapping("/list")
    public ServerResponseEntityVoid<List<SysRoleVO>> list(){
        return service.list();
    }

    /**
     * 角色列表分页查询
     * @param dto
     * @return
     */
    @GetMapping("/page")
    public ServerResponseEntityVoid<IPageIndexImg<SysRoleVO>> page(SysRoleDTO dto){
          return service.page(dto);
    }

    /**
     * 新增角色
     * @param dto
     * @return
     */
    @PostMapping
    public ServerResponseEntityVoid save(@RequestBody SysSaveRoleDTO dto){
        return service.save(dto);
    }

    /**
     * 根据id删除角色
     * @param integers
     * @return
     */
    @DeleteMapping
    public ServerResponseEntityVoid deleteByIds(@RequestBody List<Long> integers){
         return service.deleteByIds(integers);
    }

    /**
     * 根据id获取信息
     * @param roleId
     * @return
     */
    @GetMapping("/info/{roleId}")
    public ServerResponseEntityVoid<SysRoleVO> getInfoById(@PathVariable Long roleId){
       return service.getInfoById(roleId);
    }

    /**
     * 根据id更新信息
     * @param dto
     * @return
     */
    @PutMapping
    public ServerResponseEntityVoid updateInfoById(@RequestBody SysSaveRoleDTO dto){
        return service.updateInfoById(dto);
    }
}
